﻿using Help;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BLLA
{
    public partial class View_User : BaseBLL<Model.View_User>, IBLL.IView_UserBLL
    {
        ObjectSerialize os = new ObjectSerialize();
        DataResult result = new DataResult();
        #region 微信登录
        /// <summary>
        /// 微信登录
        /// </summary>
        /// <param name="AccMobile">第三方号</param>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string DCUserLogin_WeiXin(string AccMobile, string YZM, int RETID)
        {
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion
            //1.调用业务层方法 根据登陆名查询
            WriteLog.WriteW("微信登录:   " + AccMobile);
            List<Model.View_User> usr = new List<Model.View_User>();
            try
            {
                usr = base.DBSession.IView_UserDAL.GetListBy("SELECT  * FROM  View_User where AccState=1 and AccMobile='" + AccMobile + "'");
            }
            catch (Exception)
            {
                result.BS = "-1";
                result.Msg = "查询不到用户！";
                return os.StringOfObject(result, RETID);
            }
            try
            {
                //2.判断是否登陆成功
                if (usr != null && usr.Count > 0)
                {
                    result.BS = "1";
                    result.Msg = "登录成功！";
                    result.rows = usr[0];
                }
                else
                {
                    try
                    {
                        Model.Order_Key_T Key = base.DBSession.IOrder_Key_TDAL.GetListBy(u => true).First();
                        WriteLog.WriteW("微信登录查询Key");
                        if (Key.OrderYz == 0)
                        {
                            Model.View_User _User = new Model.View_User();
                            //usr = base.DBSession.IView_UserDAL.GetListBy(u => u.AccID == 0);
                            _User.AccNum = "外来用户";
                            _User.AccMobile = AccMobile;
                            _User.AccID = 0;
                            result.BS = "1";
                            result.Msg = "登录成功！";
                            result.rows = _User;
                            return os.StringOfObject(result, RETID);
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteLog.WriteW("微信登录查询验证开关异常:   " + ex.Message);
                    }


                    result.BS = "0";
                    result.Msg = "查询不到用户！";
                }
            }
            catch (Exception ex)
            {
                WriteLog.WriteW("微信登录异常:   " + ex.Message);
                result.BS = "-99";
                result.Msg = "查询不到用户！";
            }

            return os.StringOfObject(result, RETID);
        }
        #endregion
    }
}
